package com.demo.mantis.service;

import cn.techarts.dragonfly.app.AbstractService;
import com.demo.mantis.model.Book;
import com.demo.mantis.model.Friend;
import jakarta.transaction.Transactional;

import javax.inject.Singleton;
import java.util.Random;

@Singleton
public class HelloServiceImpl extends AbstractService implements HelloService {

	@Override
	@Transactional
	public String hello(int id, String greetings) {
		var helper = this.getDataHelper();
		var friend = helper.get(id, Friend.class, "getFriendById");
		if(friend == null) return null;
		return greetings + " " + friend.getName();
	}
	
	@Override
	@Transactional
	public Book buyBook(Book arg) {
		arg.setId(new Random().nextInt());
		return arg;
	}

}
